#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
struct node
{
    int T;
    int D;
}a[N];
int n;
bool cmp(node& a, node& b)
{
    return a.T * b.D < a.D * b.T;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].T >> a[i].D;
    }
    sort(a + 1, a + 1 + n, cmp);
    ll ret = 0;
    ll t = 0;
    for (int i = 1; i <= n; i++)
    {
        ret += a[i].D * t;
        t += a[i].T * 2;
    }
    cout << ret << endl;
    return 0;
}